package com.gm.service.user;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.gm.common.Pager;
import com.gm.dao.cardType.ICardTypeDao;
import com.gm.model.po.CardType;
import com.gm.tools.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/6/25.
 */
@Service
public class CardTypeService {


    @Autowired
    private ICardTypeDao cardTypeDao;


    public PageList<CardType> getCardTypeList(Pager pager){

        PageBounds pageBounds = new PageBounds(pager.getCurrentPage(), pager.getPageSize());
        return cardTypeDao.getCardTypeList(pageBounds);
    }

    public int addCardType(CardType cardType){
        cardType.setStatus(1);//卡状态 1，可用， 0 冻结 －1 删除
        cardType.setCreateTime(DateUtils.getCurrentUnixTime());
        cardType.setUpdateTime(DateUtils.getCurrentUnixTime());
        return cardTypeDao.insert(cardType);
    }

    public int updateCardType(CardType cardTypeParm){
        CardType  cardType = cardTypeDao.selectByPrimaryKey(cardTypeParm.getId());
        cardType.setName(cardTypeParm.getName());
        cardType.setUpdateTime(DateUtils.getCurrentUnixTime());
        return cardTypeDao.updateByPrimaryKey(cardType);
    }

    public int deleteCardType(Integer id){
        CardType  cardType = cardTypeDao.selectByPrimaryKey(id);
        cardType.setStatus(0);
        return cardTypeDao.updateByPrimaryKey(cardType);
    }

    public CardType selectByPrimaryKey(Integer id){
        return cardTypeDao.selectByPrimaryKey(id);
    }

    public CardType selectByName(String name){
        return cardTypeDao.selectByName(name);
    }

    public List<CardType> getCardTypeAll(){
        return cardTypeDao.getCardTypeAll();

    }
}
